The figure data structure in Python 您所在的位置:网站首页 list figures comparison The figure data structure in Python

The figure data structure in Python

#The figure data structure in Python| 来源: 网络整理| 查看: 265

The Top-Level layout Attribute¶

The second of the three top-level attributes of a figure is layout, whose value is referred to in text as "the layout" and must be a dict, containing attributes that control positioning and configuration of non-data-related parts of the figure such as:

Dimensions and margins, which define the bounds of "paper coordinates" (see below) Figure-wide defaults: templates, fonts, colors, hover-label and modebar defaults Title and legend (positionable in container and/or paper coordinates) Color axes and associated color bars (positionable in paper coordinates) Subplots of various types on which can be drawn multiple traces and which are positioned in paper coordinates: xaxis, yaxis, xaxis2, yaxis3 etc: X and Y cartesian axes, the intersections of which are cartesian subplots scene, scene2, scene3 etc: 3d scene subplots ternary, ternary2, ternary3, polar, polar2, polar3, geo, geo2, geo3, mapbox, mapbox2, mabox3, smith, smith2 etc: ternary, polar, geo, mapbox or smith subplots Non-data marks which can be positioned in paper coordinates, or in data coordinates linked to 2d cartesian subplots: annotations: textual annotations with or without arrows shapes: lines, rectangles, ellipses or open or closed paths images: background or decorative images Controls which can be positioned in paper coordinates and which can trigger Plotly.js functions when interacted with by a user: updatemenus: single buttons, toggles and dropdown menus sliders: slider controls The Top-Level frames Attribute¶

The third of the three top-level attributes of a figure is frames, whose value must be a list of dicts that define sequential frames in an animated plot. Each frame contains its own data attribute as well as other parameters. Animations are usually triggered and controlled via controls defined in layout.sliders and/or layout.updatemenus

The config Object¶

At render-time, it is also possible to control certain figure behaviors which are not considered part of the figure proper i.e. the behavior of the "modebar" and how the figure relates to mouse actions like scrolling etc. The object that contains these options is called the config, and has its own documentation page. It is exposed in Python as the config keyword argument of the .show() method on plotly.graph_objects.Figure objects.

Positioning With Paper, Container Coordinates, or Axis Domain Coordinates¶

Various figure components configured within the layout of the figure support positioning attributes named x or y, whose values may be specified in "paper coordinates" (sometimes referred to as "plot fractions" or "normalized coordinates"). Examples include layout.xaxis.domain or layout.legend.x or layout.annotation[].x.

Positioning in paper coordinates is not done in absolute pixel terms, but rather in terms relative to a coordinate system defined with an origin (0,0) at (layout.margin.l, layout.margin.b) and a point (1,1) at (layout.width-layout.margin.r, layout.height-layout.margin.t) (note: layout.margin values are pixel values, as are layout.width and layout.height). Paper coordinate values less than 0 or greater than 1 are permitted, and refer to areas within the plot margins.

To position an object in "paper" coordinates, the corresponding axis reference is set to "paper". For instance a shape's xref attribute would be set to "paper" so that the x value of the shape refers to its position in paper coordinates.

Note that the contents of the layout.margin attribute are by default computed based on the position and dimensions of certain items like the title or legend, and may be made dependent on the position and dimensions of tick labels as well when setting the layout.xaxis.automargin attribute to True. This has the effect of automatically increasing the margin values and therefore shrinking the physical area defined between the (0,0) and (1,1) points. Positioning certain items at paper coordinates less than 0 or greater than 1 will also trigger this behavior. The layout.width and layout.height, however, are taken as givens, so a figure will never grow or shrink based on its contents.

The figure title may be positioned using "container coordinates" which have (0,0) and (1,1) anchored at the bottom-left and top-right of the figure, respectively, and therefore are independent of the values of layout.margin.

Furthermore, shapes, annotations, and images can be placed relative to an axis's domain so that, for instance, an x value of 0.5 would place the object halfway along the x-axis, regardless of the domain as specified in the layout.xaxis.domain attribute. This behavior can be specified by adding ' domain' to the axis reference in the axis referencing attribute of the object. For example, setting yref = 'y2 domain' for a shape will refer to the length and position of the axis named y2.

2D Cartesian Trace Types and Subplots¶

The most commonly-used kind of subplot is a two-dimensional Cartesian subplot. Traces compatible with these subplots support xaxis and yaxis attributes whose values must refer to corresponding objects in the layout portion of the figure. For example, if xaxis="x", and yaxis="y" (which is the default) then this trace is drawn on the subplot at the intersection of the axes configured under layout.xaxis and layout.yaxis, but if xaxis="x2" and yaxis="y3" then the trace is drawn at the intersection of the axes configured under layout.xaxis2 and layout.yaxis3. Note that attributes such as layout.xaxis and layout.xaxis2 etc do not have to be explicitly defined, in which case default values will be inferred. Multiple traces of different types can be drawn on the same subplot.

X- and Y-axes support the type attribute, which enables them to represent continuous values (type="linear", type="log"), temporal values (type="date") or categorical values (type="category", type="multicategory). Axes can also be overlaid on top of one another to create dual-axis or multiple-axis charts. 2-d cartesian subplots lend themselves very well to creating "small multiples" figures, also known as facet or trellis plots.

The following trace types are compatible with 2d-cartesian subplots via the xaxis and yaxis attributes:

scatter-like trace types: scatter and scattergl, which can be used to draw scatter plots, line plots and curves, time-series plots, bubble charts, dot plots and filled areas and also support error bars bar, funnel, waterfall: bar-like trace types which can also be used to draw timelines and Gantt charts histogram: an aggregating bar-like trace type box and violin: 1-dimensional distribution-like trace types histogram2d and histogram2dcontour: 2-dimensional distribution-like density trace types image, heatmap and contour: matrix trace types ohlc and candlestick: stock-like trace types carpet: a special trace type for building carpet plots, in that other traces can use as subplots (see below) splom: multi-dimensional scatter plots which implicitly refer to many 2-d cartesian subplots at once. 3D, Polar, Ternary and Smith Trace Types and Subplots¶

Beyond 2D cartesian subplots, figures can include three-dimensional cartesian subplots, polar subplots, ternary subplots and smith subplots. The following trace types support attributes named scene, polar, smith or ternary, whose values must refer to corresponding objects in the layout portion of the figure i.e. ternary="ternary2" etc. Note that attributes such as layout.scene and layout.ternary2 etc do not have to be explicitly defined, in which case default values will be inferred. Multiple traces of a compatible type can be placed on the same subplot.

The following trace types are compatible with 3D subplots via the scene attribute, which contains special camera controls:

scatter3d, which can be used to draw individual markers, 3d bubble charts and lines and curves surface and mesh: 3d surface trace types cone and streamtube: 3d vector field trace types volume and isosurface: 3d volume trace types

The following trace types are compatible with polar subplots via the polar attribute:

scatter-like trace types: scatterpolar and scatterpolargl, which can be used to draw individual markers, curves and filled areas (i.e. radar or spider charts) barpolar: useful for wind roses and other polar bar charts

The following trace types are compatible with ternary subplots via the ternary attribute:

scatterternary, which can be used to draw individual markers, curves and filled areas

The following trace types are compatible with smith subplots via the smith attribute:

scattersmith, which can be used to draw individual markers, curves and filled areas Map Trace Types and Subplots¶

Figures can include two different types of map subplots: geo subplots for outline maps and mapbox subplots for tile maps. The following trace types support attributes named geo or mapbox, whose values must refer to corresponding objects in the layout i.e. geo="geo2" etc. Note that attributes such as layout.geo2 and layout.mapbox etc do not have to be explicitly defined, in which case default values will be inferred. Multiple traces of a compatible type can be placed on the same subplot.

The following trace types are compatible with geo subplots via the geo attribute:

scattergeo, which can be used to draw individual markers, line and curves and filled areas on outline maps choropleth: colored polygons on outline maps

The following trace types are compatible with mapbox subplots via the mapbox attribute:

scattermapbox, which can be used to draw individual markers, lines and curves and filled areas on tile maps choroplethmapbox: colored polygons on tile maps densitymapbox: density heatmaps on tile maps Traces Which Are Their Own Subplots¶

Certain trace types cannot share subplots, and hence have no attribute to map to a corresponding subplot in the layout. Instead, these traces are their own subplot and support a domain attribute for position, which enables the trace to be positioned in paper coordinates (see below). With the exception of pie and funnelarea, such traces also do not support legends (see below)

The following trace types are their own subplots and support a domain attribute:

pie and funnelarea: one-level part-to-whole relationships with legend items sunburst and treemap: hierarchical multi-level part-to-whole relationships parcoords and parcats: continuous and categorical multidimensional figures with parallel coordinates and parallel sets sankey: flow diagrams table: text-based tables indicator: big numbers, gauges, and bullet charts Carpet Trace Types and Subplots¶

Certain trace types use traces of type carpet as a subplot. These support a carpet attribute whose value must match the value of the carpet attribute of the carpet trace they are to be drawn on. Multiple compatible traces can be placed on the same carpet trace.

The following trace types are compatible with carpet trace subplots via the carpet attribute:

scattercarpet, which can be used to draw individual markers, curves and filled areas contourcarpet Trace Types, Legends and Color Bars¶

Traces of most types can be optionally associated with a single legend item in the legend. Whether or not a given trace appears in the legend is controlled via the showlegend attribute. Traces which are their own subplots (see above) do not support this, with the exception of traces of type pie and funnelarea for which every distinct color represented in the trace gets a separate legend item. Users may show or hide traces by clicking or double-clicking on their associated legend item. Traces that support legend items also support the legendgroup attribute, and all traces with the same legend group are treated the same way during click/double-click interactions.

The fact that legend items are linked to traces means that when using discrete color, a figure must have one trace per color in order to get a meaningful legend. Plotly Express has robust support for discrete color to make this easy.

Traces which support continuous color can also be associated with color axes in the layout via the coloraxis attribute. Multiple traces can be linked to the same color axis. Color axes have a legend-like component called color bars. Alternatively, color axes can be configured within the trace itself.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有